// **************************************************
// Table 6: Decomposing the density distance gradient
// **************************************************

// Writes the results as reg_montreal to $resultpath/tables/

use "$outpath/database_for_reg.dta", clear

eststo clear

gen Lnetage = log(etage_role)
	

global instruct "tdec(3) rdec(3) auto(3) bdec(3) dec(3) symbol($^a$,$^b$,$^c$) se e(r2_p) tex label nocons"

xi: reghdfe Lnland_fwc_role dist_min_NEW i.cat0 number_NEQ number_NEQ2 number_NEQ3 number_NEQ4 Lnemp i.hoffice i.exports NBdiffbusiness NBdiffnaics4 NBdiffproduct Lndist_maj_air Lndist_stat_freight Lndist_junction if samplep==1&mtl_in==1&etage_role!=.&P_area_role!=.&ratio_bis!=., absorb(naics4d eruid) vce(robust)
outreg2 using "$resultpath/tables/reg_decomposition.xls", replace $instruct keep(dist_min_NEW _Icat0_2  _Icat0_3 _Ihoffice_2  _Iexports_2 number_NEQ number_NEQ2 number_NEQ3 number_NEQ4 Lnemp  NBdiffbusiness NBdiffnaics4 NBdiffproduct  Lndist_maj_air Lndist_stat_freight Lndist_junction) ctitle(Ln Floorspace per worker)

xi: reghdfe Lnland_pwc_role dist_min_NEW i.cat0 number_NEQ number_NEQ2 number_NEQ3 number_NEQ4 Lnemp i.hoffice i.exports NBdiffbusiness NBdiffnaics4 NBdiffproduct Lndist_maj_air Lndist_stat_freight Lndist_junction if samplep==1&mtl_in==1&etage_role!=.&F_area_role!=.&ratio_bis!=., absorb(naics4d eruid) vce(robust)
outreg2 using "$resultpath/tables/reg_decomposition.xls", append $instruct keep(dist_min_NEW _Icat0_2  _Icat0_3 _Ihoffice_2  _Iexports_2 number_NEQ number_NEQ2 number_NEQ3 number_NEQ4 Lnemp  NBdiffbusiness NBdiffnaics4 NBdiffproduct  Lndist_maj_air Lndist_stat_freight Lndist_junction) ctitle(Ln Percel size per worker)

xi: reghdfe Lnetage dist_min_NEW i.cat0 number_NEQ number_NEQ2 number_NEQ3 number_NEQ4 Lnemp i.hoffice i.exports NBdiffbusiness NBdiffnaics4 NBdiffproduct Lndist_maj_air Lndist_stat_freight Lndist_junction if samplep==1&mtl_in==1&F_area_role!=.&P_area_role!=.&ratio_bis!=., absorb(naics4d eruid) vce(robust)
outreg2 using "$resultpath/tables/reg_decomposition.xls", append $instruct keep(dist_min_NEW _Icat0_2  _Icat0_3 _Ihoffice_2  _Iexports_2 number_NEQ number_NEQ2 number_NEQ3 number_NEQ4 Lnemp  NBdiffbusiness NBdiffnaics4 NBdiffproduct  Lndist_maj_air Lndist_stat_freight Lndist_junction) ctitle(Ln Nb floors)

xi: reghdfe ratio_bis dist_min_NEW i.cat0 number_NEQ number_NEQ2 number_NEQ3 number_NEQ4 Lnemp i.hoffice i.exports NBdiffbusiness NBdiffnaics4 NBdiffproduct Lndist_maj_air Lndist_stat_freight Lndist_junction if samplep==1&mtl_in==1&etage_role!=.&F_area_role!=., absorb(naics4d eruid)  vce(robust)
outreg2 using "$resultpath/tables/reg_decomposition.xls", append $instruct keep(dist_min_NEW _Icat0_2  _Icat0_3 _Ihoffice_2  _Iexports_2 number_NEQ number_NEQ2 number_NEQ3 number_NEQ4 Lnemp  NBdiffbusiness NBdiffnaics4 NBdiffproduct  Lndist_maj_air Lndist_stat_freight Lndist_junction) ctitle(Ln Building footprint over parcel size)


gen toto=Lnland_pwc_role-Lnetage-ratio_bis
 
xi: reghdfe toto dist_min_NEW i.cat0 number_NEQ number_NEQ2 number_NEQ3 number_NEQ4 Lnemp i.hoffice i.exports NBdiffbusiness NBdiffnaics4 NBdiffproduct Lndist_maj_air Lndist_stat_freight Lndist_junction if samplep==1&mtl_in==1&etage_role!=.&F_area_role!=., absorb(naics4d eruid)  vce(robust)
outreg2 using "$resultpath/tables/reg_decomposition.xls", append $instruct keep(dist_min_NEW _Icat0_2  _Icat0_3 _Ihoffice_2  _Iexports_2 number_NEQ number_NEQ2 number_NEQ3 number_NEQ4 Lnemp  NBdiffbusiness NBdiffnaics4 NBdiffproduct  Lndist_maj_air Lndist_stat_freight Lndist_junction) ctitle((2)+(3)+(4))
